package com.kaibes.module.permission.db.service;

import java.util.List;

import org.springframework.stereotype.Service;

import com.kaibes.core.base.option.BooleanOptions;
import com.kaibes.core.base.option.NullOptions;
import com.kaibes.core.base.util.IntegerUtils;
import com.kaibes.core.base.util.ListUtils;
import com.kaibes.module.permission.db.entity.Role;
import com.kaibes.orm.curd.QueryBuilder;
import com.kaibes.web.api.ResponseServiceImpl;

@Service
public class RoleService extends ResponseServiceImpl<Role> {
    
    public String getNameById(Integer id) {
        return NullOptions.returnString(
                BooleanOptions.returnObject(
                        IntegerUtils.isNotZero(id), ()->get(QueryBuilder.newBuilder().eq("id", id).build(), "name")),
                role->role.getName());
    }
    
    public List<Long> listIdByNameLike(String name) {
        return ListUtils.toLong(
                list(QueryBuilder.newBuilder().like("name", name).build(), "id")
                , role->role.getId());
    }
    
}